package cn.seqdata.forecast.model.arima;

import com.workday.insights.timeseries.arima.Arima;
import com.workday.insights.timeseries.arima.struct.ArimaParams;
import com.workday.insights.timeseries.arima.struct.ForecastResult;

import cn.seqdata.forecast.model.AbstractModel;
import cn.seqdata.forecast.model.ModelParams;

public class ArimaModel extends AbstractModel<ModelParams> {
	private double[] values;
	private ArimaParams params;

	@Override
	public void learn(double[] values) {
		this.values = values;
	}

	@Override
	public double[] forecast(int n) {
//		int p = 1, d = 2, q = 1;
//		ArimaParams params = new ArimaParams(p, d, q, p + 1, d + 1, q + 1, 96);
		ForecastResult r = Arima.forecast_arima(values, n, params);
		return r.getForecast();
	}

	@Override
	public AbstractModel<ModelParams> create(ModelParams params) {
		ArimaModel model = new ArimaModel();

		model.setParams(params);
		model.params = new ArimaParams(params.getInteger("p"), params.getInteger("d"), params.getInteger("q"),	//
				params.getInteger("_p"), params.getInteger("_d"), params.getInteger("_q"), params.getInteger("m"));

		return model;
	}
}
